@extends('home.public.base')

@section('title', '商品详情')

@section('content')

    @if($cartDatas['total_rows'] == 0)

            <div class="shopping-none center bg-fff tc">
                <p class="f-999 f16">购物车中没有礼物</p>
                <p class="t-line tl f16"><a href="/">继续购物</a></p>
            </div>
        </div>
    @else
        <div class="shopping-cart center bg-fff tc">
            <table>
                <thead>
                <tr>
                    <td width="50%" class="info tl">商品信息</td>
                    <td width="10%">单价</td>
                    <td width="10%">数量</td>
                    <td width="10%">小计</td>
                    <td width="10%">操作</td>
                </tr>
                </thead>
                <tbody id="cart_list">
                @foreach($cartDatas['goods'] as $key=> $good )
                    <tr data-rec-id="1346913">
                        <td class="info tl">
                            <a href="/goods/{{$good['id']}}">
                                <img src="{{$good['options']['imgs']}}" class="dib m-r-5"></a>
                            <div class="dib">
                                <p><a href="/goods/{{$good['id']}}">{{$good['name']}}</a></p>
                                <p class="f12">
                                    <span class="f-666">{{$good['name']}} <code> {{$good['options']['lists']}} </code> </span>
                                </p>
                            </div>
                        </td>
                        <td>￥{{$good['price']}}</td>
                        <td>
                            <div class="dib count-box">
                                <input type="text" sid="{{$key}}" value="{{$good['num']}}"
                                       class="cartnum dib tc icon-number">
                            </div>
                        </td>

                        <td id="sub_total_1346913">￥{{$good['total']}}</td>
                        <td><a href="javascript:void(0)" class="delcart icon-bgr icon-delete" sid="{{$key}}"></a></td>
                    </tr>

                @endforeach

                </tbody>
            </table>
            <div class="cart-btm clear f16">
                <div class="fl tl"><a href="/" class="dib m-t-5">
                        <i class="icon-bgr icon-page-l m-r-10"></i>继续购物</a>
                </div>

                <div class="fr tr">
                    <span>共 {{$cartDatas['total_rows']}} 件商品</span>
                    <span class="m-l-20">   合计：
                    <b class="f18 f-d93732" id="goods-total">￥{{$cartDatas['total'] }}</b></span>
                    <a href="/order" class="btn-red-sml f14 m-l-80 ani-bg">去结账</a>
                </div>
            </div>
        </div>
        <script>
            $(function () {
                $.ajaxSetup({
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    }
                });

                //更新购物车数量
                $("input.cartnum").change(function () {
                    //商品sid
                    var sid = $(this).attr('sid');
                    //数量
                    var num = $(this).val();
                    var data = {
                        sid: sid,
                        num: num
                    };
                    $.post("/upcart", data, function (result) {
                        if (result == 'ok') {
                            location.reload();
                        }
                    });
                });

                //删除物品
                $(".delcart").click(function () {
                    //商品sid
                    var sid = $(this).attr('sid');
                    var data = {
                        sid: sid
                    };
                    $.post("/delcart", data, function (result) {
                        if (result == 'ok') {
                            location.reload();
                        }
                    });
                });

            })

        </script>

    @endif

@endsection